package com.khotyn.heresy.service;

import com.khotyn.heresy.bean.PagedBean;
import com.khotyn.heresy.dao.PicCommentDAO;

/**
 * 评论列表服务类
 * 
 * @author 黄挺
 * 
 */
public class CommentListService {
	private PicCommentDAO picCommentDAO;
	private static int pageSize = 10;

	/**
	 * 评论列表服务函数
	 * 
	 * @param pictureID 图片ID
	 * @param userID 用户ID
	 * @param page 分页页码
	 * @param requestURL 请求URL
	 * @return 分页Bean
	 */
	public PagedBean doService(String pictureID, Integer userID, Integer page) {
		PagedBean pagedBean = new PagedBean();
		pagedBean.setPageNum(page);
		pagedBean.setPageSize(pageSize);

		return doDBOperate(pictureID, page, pagedBean);
	}

	/**
	 * 评论列表数据库操作函数
	 * 
	 * @param pictureID 图片ID
	 * @param page 分页页码
	 * @param browseLog 日志Bean
	 * @param pagedBean 分页Bean
	 * @return
	 */
	private PagedBean doDBOperate(String pictureID, Integer page, PagedBean pagedBean) {
		int minRow = (page - 1) * pageSize + 1;
		int maxRow = page * pageSize;

		pagedBean.setPagedItem(picCommentDAO.selectPagedCommentByPicID(pictureID, minRow, maxRow));
		pagedBean.setItemNum(picCommentDAO.selectCommentCountByPicId(pictureID));
		int maxPage = (int) java.lang.Math.ceil((double) pagedBean.getItemNum() / (double) pageSize);
		pagedBean.setMaxPage(maxPage);

		return pagedBean;
	}

	public void setPicCommentDAO(PicCommentDAO picCommentDAO) {
		this.picCommentDAO = picCommentDAO;
	}

}
